/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Pojo.DanhMuc;
import Util.MySqlDataAccessHelper;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author USER
 */
public class DanhMucDAO {
    //Lấy danh mục chi tiết từ mã danh mục sản phẩm
    public static List<DanhMuc> getList(int maDMSP){
        List<DanhMuc> dmcts = new ArrayList<DanhMuc>();
        
        try{
            String sql = String.format("SELECT * FROM danh_muc WHERE ma_danh_muc=%d", maDMSP);
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while(rs.next()){
               DanhMuc danhMuc = new DanhMuc();
               danhMuc.setMaDanhMuc(rs.getInt("ma_danh_muc"));
               danhMuc.setTenDanhMuc(rs.getString("ten_danh_muc"));
               danhMuc.setMaLoaiSach(rs.getInt("ma_loai_sach"));
               
               dmcts.add(danhMuc);
            }
            helper.close();
        }catch(Exception e){
            
        }
        
        return dmcts;
    }
}
